<%@ page import="dao.UsersManager" %>
<%--
Created by IntelliJ IDEA.
User: Zafkiel
Date: 2021/8/14
Time: 18:25
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
		<title>靓仔购物网 - 注册</title>

		<!--用百度的静态资源库的cdn安装bootstrap环境-->
		<!-- Bootstrap 核心 CSS 文件 -->
		<link href="./css/bootstrap.min.css" rel="stylesheet">
		<!--font-awesome 核心我CSS 文件-->
		<link href="font-awesome-4.7.0/css/font-awesome.min.css" rel="stylesheet">
		<!-- 在bootstrap.min.js 之前引入 -->
		<script src="./js/jquery-3.2.1.min.js"></script>
		<!-- Bootstrap 核心 JavaScript 文件 -->
		<script src="./js/bootstrap.min.js"></script>
		<script src="./js/sha256.min.js"></script>
        <script src="./js/account.js"></script>
		<link rel="stylesheet" href="css/login.css">

	</head>
	<body>
		<!-- 头部 logo -->
		<header class="container">
			<div class="row" style="padding-top: 20px;">
				<div class="col-md-2"><a href="#"><img src="img/logo.png" /></a></div>
				<div class="col-md-2" style="font-size: 30px; line-height: 70px;">欢迎注册</div>
			</div>
		</header>

		<!-- body 背景图片 和 表单 -->
		<div class="container body">
			<div class="form row formRow">
				<form id="registForm" action="<%=application.getContextPath()%>/register.userInfoService" method="post">
					<div class="loginFormBox">
					<h3 class="form-title">注册</h3>
						<div class="form-group">
							<!--        用户名图标和用户名输入框            -->
							<i class="fa fa-user" aria-hidden="true"></i>
							<input class="form-control required" type="text" name="username" id="username"
								placeholder="请输入用户名" required>
						</div>
						
						<!--        密码图标和密码输入框                -->
						<div class="form-group">
							<i class="fa fa-key" aria-hidden="true"></i>
							<input class="form-control required" type="password" name="password" id="password"
								placeholder="请输入密码" required>
						</div>
						<!--          确认密码              -->
						<div class="form-group">
							<i class="fa fa-check-circle-o" aria-hidden="true"></i>
							<input class="form-control required" type="password" name="resetpw" id="resetpw"
								placeholder="请确认密码" required>
						</div>
						<!--        用户昵称       -->
						<div class="form-group">
							<i class="fa fa-phone" aria-hidden="true"></i>
							<input class="form-control required" type="text" name="usernick" id="usernick"
								placeholder="昵称" required>
						</div>

						<div class="form-group">
						</div>

						<!--注册按钮-->
						<div class="form-group">
							<input type="button" value="注册" id="btn-register" class="btn btn-success pull-right">
							<a class="btn btn-info pull-left" id="back_btn" value="返回" href="login.jsp">返回</a>
						</div>
					</div>
				</form>
			</div>
		</div>
		<script type="text/javascript">
			$(function(){

				<%
				UsersManager.UserDAOOptionResult state = (UsersManager.UserDAOOptionResult)session.getAttribute("OEStoreRegisterInfo");
				if(state != null) {
					switch(state) {
						case DUP_UNAME:           %>alert("注册失败，用户名和别人重复了哟");<%          break;
						case DUP_UNIKE:           %>alert("注册失败，昵称和别人重复了哟");<%            break;
						case FAIL_UNKNOW:default: %>alert("注册失败，也不知道为啥反正就是失败了 T^T");<% break;
					}
				}
				%>

				$("#btn-register").click(function(){
					var uname = $("#username").val();
					var upass = $("#password").val();
					var confm = $("#resetpw").val();
					var unick = $("#usernick").val();

					if(uname == null  ||  uname == ""  ||  upass == null  ||  upass == ""  ||  confm == null  || confm == ""  ||  unick == null  ||  unick == "") alert("请填写完整的字段");
					else {
						if(confm == upass) {
							document.getElementById("btn-register").disabled = true;
							if(accountStrTest(uname) && accountStrTest(upass) && idStrTest(unick)) {
								//register(uname, upass, unick);
								document.getElementById("resetpw").disabled = true;
								$("#registForm").submit();
								document.getElementById("resetpw").disabled = false;
							}
							else {
								alert("用户名和密码应该为8到16个字符，昵称不能含有特殊符号");
								$("#password").prop("value", "");
								$("#resetpw").prop("value", "");
								document.getElementById("btn-register").disabled = false;
							}
						}
						else {
							alert("两次输入的口令不一致喔");
							$("#password").prop("value", "");
							$("#resetpw").prop("value", "");
						}
					}
				})
			});
		</script>
	</body>
</html>
